package LeetCode.MovingAverage041;

import java.util.LinkedList;
import java.util.Queue;

public class MovingAverage {
    private int size;
    private int sum;
    private Queue<Integer> queue;

    MovingAverage(int size) {
        this.size = size;
        queue = new LinkedList<>();
        sum = 0;
    }

    public double next(int val) {
        if (queue.size() >= this.size){
            sum -= queue.poll();
        }
        queue.add(val);
        sum += val;
        System.out.println("sum --> "+sum);
        return ((float)sum)/queue.size();
    }
}
